﻿<%@ page language="java" import="java.util.*,com.ruohi.util.common.*" pageEncoding="UTF-8"%><%
	String tablePrefix = Env.getInstance().getProperty("table_prefix");
	String tableName = "gift_friendly_link";
	String channelUUID = CommonString.getFormatPara(request.getParameter("channel_uuid"));
	String fileds = "id,add_user,add_date,uuid,title,link_url,is_show,type";
	String whereStr = "";
	String orderByStr = " id asc";

%><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <title><%=Env.getInstance().getProperty("project_name") %></title>
	<link href="/plugin/ui/ligerUI/ligerUI/skins/Aqua/css/ligerui-all.css" rel="stylesheet" type="text/css" />
	<link href="/plugin/ui/ligerUI/ligerUI/skins/Gray/css/all.css" rel="stylesheet" type="text/css" />
	<link href="/plugin/ui/ligerUI/ligerUI/skins/ligerui-icons.css" rel="stylesheet" type="text/css" />
	<link href="/backend/style/style.css" rel="stylesheet" type="text/css" />
	<script src="/plugin/jquery/jquery.min.js" type="text/javascript"></script>
  </head>
  <body>

	<div style="clear: left;"></div>
	<div class="l-loading" style="display: block" id="pageloading"></div> 
	<div id="maingrid" style="margin: 0; padding: 0"></div>
	<div style="display: none;"></div>
  </body>
</html>
<script src="/plugin/ui/ligerUI/ligerUI/js/ligerui.min.js" type="text/javascript"></script>
<script src="/backend/scripts/common.js" prefix="<%=tablePrefix %>" type="text/javascript"></script>
<script type="text/javascript">
	var grid;
	var tableName = "<%=tableName %>";
	var channelUUID = '<%=channelUUID%>';
	var fields = "<%=fileds %>";
	var whereStr = "<%=whereStr %>";
	var orderBy = "<%=orderByStr %>";
	var columnsArr = [];
	var url = "";
	var conditionStr = "";
	var params = [];
	var myToolbar = {
        items: [{
            text: '增加',
            click: function(){
                addAndEdit(undefined, false);
            },
            icon: 'add'
        },{
        	text: "删除",
        	click: function(){
										toolbarDel({
											tableName:'gift_friendly_link',
											channel_uuid:'<%=channelUUID %>'
										});
        	},
        	icon: "delete"
        }]
    };
	jQuery(function() {
		params.push({'name':'enumNo','value':'106013','fileName':'test'});
		grid = new Dev21sunGrid({
			toolbar:myToolbar
			});
		jQuery("#pageloading").hide();
	});
	//列数组
	columnsArr =  [ 
	{ display : '标题', name : 'title'  , id : 'no', align : 'left' , type : 'string' , width : 200, render : function(row){
			return "<a class='link' href='javascript:void(0);' onclick='addAndEdit("+row.__index+");'>"+row.title+"</a>";
		}} ,
	{ display : '显示位置', name : 'type'  , align : 'left' , type : 'string' , width : 200,render:function(row){
		var typeStr = "首页";
		if(row.type=='2'){
			typeStr = "聚定制";
		}else if(row.type=='3'){
			typeStr = "模型超市";
		}
		return typeStr;
	}} ,
	{ display : '地址', name : 'link_url'  , align : 'left' , type : 'string' , width : 200} 

	];
	
	function viewComment(product_no){
		jrWindow("/backend/gift.21-sun.com/gift_product_comment/gift_product_comment_list.jsp?product_no=" + product_no, "查看评价", 800, 630);
	}
	
	function addAndEdit(index){
		if(undefined==index){//如果是增加
			toolbarAdd({
				width:650,
				height:180,
				title:"增加",
				folderName:'/gift.21-sun.com/gift_link/',
				fileName:'gift_link',
				params : {
	    			channel_uuid : "<%=channelUUID %>"
	    		}
			});
		}else{//如果是修改
	    	var row = grid.getRow(index);
	    	toolbarAdd({width:650,height:180,title:'编辑',folderName:'/gift.21-sun.com/gift_link/',fileName:'gift_link',},row.uuid);
		}
    }

	
/**
 * 新品推荐方法
 * 
 * @param {}
 *            arg 推荐时要传的参数
 */
function setRec(state) {
	var art;
	if (typeof(arg) == 'undefined' || arg == null) {
		arg = {};
	}
	var checkedRows = grid.getCheckedRows();
	if (checkedRows.length <= 0) {
		return;
	}
	// 遍历所有的选中行，如果是没有UUID，则移除
	jQuery.each(checkedRows, function(index, data) {
				if (typeof(this.uuid) == 'undefined') {
					jrDeleteRow(this.__index);
				}
			});
	jrConfirm("确定推荐选中项吗？", function(v) {
				if (v) {
					var checkedRows = grid.getCheckedRows();
					var idStr = "";
					for (var i = 0; i < checkedRows.length; i++) {
						idStr += "'" + checkedRows[i].uuid + "',";
					}
					if (idStr.indexOf(",") != -1) {
						idStr = idStr.substring(0, idStr.length - 1);
					}
					arg.del_id = idStr;
					if ('undefined' == typeof(arg.tableName)) {
						arg.tableName = tableName;
					}
					arg.state = state;
					executeRec(arg);
				}
			});
}

/**
 * 执行删除的方法
 * 
 * @param {}
 *            data 要传向后台的数据
 */
function executeRec(data) {
	var enumNo = '';
	for (var i = 0; i < params.length; i++) {
		if (params[i].name == 'enumNo') {
			enumNo = params[i].value;
		}
	}
	jQuery.ajax({
				url : '/backend/action/ajax_cud.jsp?enumNo=' + enumNo + '&flag=setRec',
				data : data,
				type : 'post',
				async : false,
				cache : false,
				success : function(data) {
					grid.loadData();
				}
			});
}

</script>